package com.qing.cmsservice.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qing.cmsservice.entity.pojo.CrmBanner;
import com.qing.cmsservice.service.CrmBannerService;
import com.qing.servicebase.utils.ResponseResult;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 首页banner表 前端控制器
 * </p>
 *
 * @author Yjx
 * @since 2022-09-14
 */
@RestController
@RequestMapping("/cmsservice/banner")
@CrossOrigin
public class CrmBannerController {

    private final CrmBannerService bannerService;

    public CrmBannerController(CrmBannerService bannerService) {
        this.bannerService = bannerService;
    }

    @GetMapping("/page/{page}/{pageSize}")
    public ResponseResult index(@PathVariable int page, @PathVariable int pageSize) {
        Page<CrmBanner> pageParam = new Page<>(page, pageSize);
        return bannerService.pageBanner(pageParam,null);
    }

    @GetMapping("/get/{id}")
    public ResponseResult get(@PathVariable String id) {
        return bannerService.getBannerById(id);
    }

    @PostMapping("/add")
    public ResponseResult save(@RequestBody CrmBanner banner) {
        return bannerService.saveBanner(banner);
    }

    @PutMapping("/update")
    public ResponseResult updateById(@RequestBody CrmBanner banner) {
        return bannerService.updateBannerById(banner);
    }

    @DeleteMapping("/delete/{id}")
    public ResponseResult remove(@PathVariable String id) {
        return bannerService.removeBannerById(id);
    }

}

